package com.hsck.order.kds

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import com.hjq.toast.Toaster
import com.hsck.order.kds.base.isnoam.log.XFrame
import com.hsck.order.kds.base.utils.MyBlackToastStyle
import com.hsck.order.kds.login.loginLib
import com.hsck.order.kds.main.fragment.bake.vm.bakeLib
import com.hsck.order.kds.main.fragment.noodles.vm.noodlesLib
import com.hsck.order.kds.main.fragment.record.vm.recordLib
import com.hsck.order.kds.main.fragment.return_deishe.vm.returnLib
import com.hsck.order.kds.main.fragment.standard.vm.standardLib
import me.jessyan.autosize.AutoSizeConfig
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin

class AppApplication : Application() {
    private val libList = mutableListOf(
        loginLib, standardLib, bakeLib, noodlesLib, recordLib,
        returnLib, recordLib
    )

    override fun onCreate() {
        super.onCreate()
        context = this
        XFrame.initXLog()
        XFrame.init(this)
        val toastStyle = MyBlackToastStyle()
        Toaster.init(this, toastStyle)
        initKoin()
        AutoSizeConfig.getInstance().isCustomFragment = true
    }

    companion object {
        @SuppressLint("StaticFieldLeak")
        lateinit var context: Context
    }

    private fun initKoin() {
        startKoin {
            androidLogger()
            androidContext(this@AppApplication)
            modules(libList)
        }
    }
}